package runnable.germmy;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;



public class RunnableTest2 {

	
	private int i;
	
	public static void main(String[] args) {
		
		RunnableTest2 rtm=new RunnableTest2();
		Inc inc=rtm.new Inc();
		Dec dec=rtm.new Dec();
		
		
		
		for(int i=0;i<2;i++){
			new Thread(inc).start();
			new Thread(dec).start();
		}
	}
	
	
	
	public synchronized void increment(){
		for(int j=0;j<100;j++){
			i++;
			System.out.println(Thread.currentThread().getName()+"^_^inc^_^,i的值为"+i);
		}
	}
	
	public synchronized void decrement(){
		for(int j=0;j<100;j++){
			i--;
			System.out.println(Thread.currentThread().getName()+"^_^dec^_^,i的值为"+i);
		}
	}
	
	//内部类
	class Inc implements Runnable{
		public void run() {
			increment();
		}
	}
	
	
	//内部类
	class Dec implements Runnable{
		public void run() {
			decrement();
		}
	}
	
}

